ExcPath=
Name=
IconPath=
RootPath=

function getFileName(){
path=$1
#得到文件名
fileName=${path##*/}
#去除后缀
fileName=${fileName%.*}
echo $fileName
}

function getRootPath(){
path=$1
rootPath=${path%/*}
echo $rootPath
}


if [ ! -n "$1" ];then
echo '未输入快捷方式执行文件路径'
echo 'usage: bash make-shortcut.sh [ ExcPath , ApplicationName , IconPath ]'
echo 'or'
echo 'bash make-shortcut.sh [ ExcPath ]'
exit
else
ExcPath=$1
RootPath=$(getRootPath $ExcPath)
fi


if [ ! -n "$2" ];then
Name=$(getFileName $ExcPath)
else
Name=$2
fi

if [ ! -n "$3" ];then
if [ -f $RootPath"/"$Name".bmp" ];then
IconPath=$RootPath"/"$Name".bmp"
fi

if [ -f $RootPath"/"$Name".ico" ];then
IconPath=$RootPath"/"$Name".ico"
fi

if [ -f $RootPath"/"$Name".png" ];then
IconPath=$RootPath"/"$Name".png"
fi

if [ -f $RootPath"/"$Name".jpg" ];then
IconPath=$RootPath"/"$Name".jpg"
fi
else
IconPath=$3
fi

#应用分类默认就开发了,要改自己改一下吧
cat > /usr/share/applications/$Name".desktop" <<EOF
[Desktop Entry]
Type=Application
Terminal=false 
Name=$Name
Categories=Development
Icon=$IconPath
Exec=$ExcPath
EOF

#在当前路径下再生成一个快捷方式
cat > $Name".desktop" <<EOF
[Desktop Entry]
Type=Application
Terminal=false 
Name=$Name
Categories=Development
Icon=$IconPath
Exec=$ExcPath
EOF

